﻿using System;
using UnityEngine;

namespace RootMotion.FinalIK
{
	// Token: 0x02000027 RID: 39
	[AddComponentMenu("Scripts/RootMotion.FinalIK/IK/Full Body Biped IK")]
	[HelpURL("https://www.youtube.com/watch?v=7__IafZGwvI&index=1&list=PLVxSIA1OaTOu8Nos3CalXbJ2DrKnntMv6")]
	public class FullBodyBipedIK : IK
	{
		// Token: 0x06000205 RID: 517 RVA: 0x0000368C File Offset: 0x0000188C
		[ContextMenu("User Manual")]
		public override void OpenUserManual()
		{
			Application.OpenURL("http://www.root-motion.com/finalikdox/html/page6.html");
		}

		// Token: 0x06000206 RID: 518 RVA: 0x00003698 File Offset: 0x00001898
		[ContextMenu("Scrpt Reference")]
		public override void OpenScriptReference()
		{
			Application.OpenURL("http://www.root-motion.com/finalikdox/html/class_root_motion_1_1_final_i_k_1_1_full_body_biped_i_k.html");
		}

		// Token: 0x06000207 RID: 519 RVA: 0x000036A4 File Offset: 0x000018A4
		[ContextMenu("TUTORIAL VIDEO (SETUP)")]
		public void OpenSetupTutorial()
		{
			Application.OpenURL("https://www.youtube.com/watch?v=7__IafZGwvI");
		}

		// Token: 0x06000208 RID: 520 RVA: 0x000036B0 File Offset: 0x000018B0
		[ContextMenu("TUTORIAL VIDEO (INSPECTOR)")]
		public void OpenInspectorTutorial()
		{
			Application.OpenURL("https://www.youtube.com/watch?v=tgRMsTphjJo");
		}

		// Token: 0x06000209 RID: 521 RVA: 0x00002E24 File Offset: 0x00001024
		[ContextMenu("Support Group")]
		public void SupportGroup()
		{
			Application.OpenURL("https://groups.google.com/forum/#!forum/final-ik");
		}

		// Token: 0x0600020A RID: 522 RVA: 0x00002E30 File Offset: 0x00001030
		[ContextMenu("Asset Store Thread")]
		public void ASThread()
		{
			Application.OpenURL("http://forum.unity3d.com/threads/final-ik-full-body-ik-aim-look-at-fabrik-ccd-ik-1-0-released.222685/");
		}

		// Token: 0x0600020B RID: 523 RVA: 0x000036BC File Offset: 0x000018BC
		public void SetReferences(BipedReferences references, Transform rootNode)
		{
			this.references = references;
			this.solver.SetToReferences(this.references, rootNode);
		}

		// Token: 0x0600020C RID: 524 RVA: 0x000036D7 File Offset: 0x000018D7
		public override IKSolver GetIKSolver()
		{
			return this.solver;
		}

		// Token: 0x0600020D RID: 525 RVA: 0x0002205C File Offset: 0x0002025C
		public bool ReferencesError(ref string errorMessage)
		{
			if (BipedReferences.SetupError(this.references, ref errorMessage))
			{
				return true;
			}
			if (this.references.spine.Length == 0)
			{
				errorMessage = "References has no spine bones assigned, can not initiate the solver.";
				return true;
			}
			if (this.solver.rootNode == null)
			{
				errorMessage = "Root Node bone is null, can not initiate the solver.";
				return true;
			}
			if (this.solver.rootNode != this.references.pelvis)
			{
				bool flag = false;
				for (int i = 0; i < this.references.spine.Length; i++)
				{
					if (this.solver.rootNode == this.references.spine[i])
					{
						flag = true;
						break;
					}
				}
				if (!flag)
				{
					errorMessage = "The Root Node has to be one of the bones in the Spine or the Pelvis, can not initiate the solver.";
					return true;
				}
			}
			return false;
		}

		// Token: 0x0600020E RID: 526 RVA: 0x00022130 File Offset: 0x00020330
		public bool ReferencesWarning(ref string warningMessage)
		{
			if (BipedReferences.SetupWarning(this.references, ref warningMessage))
			{
				return true;
			}
			Vector3 vector = this.references.rightUpperArm.position - this.references.leftUpperArm.position;
			Vector3 vector2 = this.solver.rootNode.position - this.references.leftUpperArm.position;
			float num = Vector3.Dot(vector.normalized, vector2.normalized);
			if (num > 0.95f)
			{
				warningMessage = "The root node, the left upper arm and the right upper arm bones should ideally form a triangle that is as close to equilateral as possible. Currently the root node bone seems to be very close to the line between the left upper arm and the right upper arm bones. This might cause unwanted behaviour like the spine turning upside down when pulled by a hand effector.Please set the root node bone to be one of the lower bones in the spine.";
				return true;
			}
			Vector3 vector3 = this.references.rightThigh.position - this.references.leftThigh.position;
			Vector3 vector4 = this.solver.rootNode.position - this.references.leftThigh.position;
			num = Vector3.Dot(vector3.normalized, vector4.normalized);
			if (num > 0.95f)
			{
				warningMessage = "The root node, the left thigh and the right thigh bones should ideally form a triangle that is as close to equilateral as possible. Currently the root node bone seems to be very close to the line between the left thigh and the right thigh bones. This might cause unwanted behaviour like the hip turning upside down when pulled by an effector.Please set the root node bone to be one of the higher bones in the spine.";
				return true;
			}
			return false;
		}

		// Token: 0x0600020F RID: 527 RVA: 0x000036DF File Offset: 0x000018DF
		[ContextMenu("Reinitiate")]
		public void Reinitiate()
		{
			this.SetReferences(this.references, this.solver.rootNode);
		}

		// Token: 0x06000210 RID: 528 RVA: 0x0002223C File Offset: 0x0002043C
		[ContextMenu("Auto-detect References")]
		public void AutoDetectReferences()
		{
			this.references = new BipedReferences();
			BipedReferences.AutoDetectReferences(ref this.references, base.transform, new BipedReferences.AutoDetectParams(true, false));
			this.solver.rootNode = IKSolverFullBodyBiped.DetectRootNodeBone(this.references);
			this.solver.SetToReferences(this.references, this.solver.rootNode);
		}

		// Token: 0x04000121 RID: 289
		public BipedReferences references = new BipedReferences();

		// Token: 0x04000122 RID: 290
		public IKSolverFullBodyBiped solver = new IKSolverFullBodyBiped();
	}
}
